package com.zx._10_设计模式.行为型模式.责任链模式.demo2;

import java.util.ArrayList;
import java.util.List;

/**
 * 责任链--执行器(列表形式)
 *
 * @date: 2019年6月18日上午10:21:06
 */
public class ChianHandlerListProcess {

    private List<ChianHandler> firstHandler;

    public ChianHandlerListProcess() {
        this.firstHandler = new ArrayList<>();
        this.firstHandler.add(new Demo1ChianHandler());
        this.firstHandler.add(new Demo2ChianHandler());
        this.firstHandler.add(new Demo3ChianHandler());

    }

    public boolean process() {
        boolean result = true;
        for (ChianHandler chianHandler : this.firstHandler) {
            if (!chianHandler.run()) {
                result = false;
                break;
            }
        }

        return result;
    }

}
